<template>
  <view class="box">
    <view v-for="(item, index) in list" :key="index" class="contain">
      <view class="contain_box">
        <text class="contain_left">用车申请人</text>
        <text>{{ userList.find(item=>item.value===item.applyPeopleId).name  }}</text>
        <text style="font-size: 13px; color: #aaaaaa; padding-left: 20%">{{
          item.createTime
        }}</text>
      </view>
      <view class="contain_box">
        <text class="contain_left">用车时间</text>
        <text>{{ item.useTime }}</text>
      </view>
      <view class="contain_box">
        <text class="contain_left">起始地</text>
        <text>{{ getPass(item.driveInfoList, "origin") }}</text>
      </view>
      <view class="contain_box">
        <text class="contain_left">途径地</text>
        <text>{{ getPass(item.driveInfoList, "pass") }}</text>
      </view>
      <view style="display: flex" class="contain_box">
        <text class="contain_left">用车人数</text>
        <text>{{ item.usePeopleNum }}</text>
        <u-button
          style="width: 25%; margin-left: 40%"
          type="primary"
          text="上传回执"
          @click="uploadFile(item)"
        ></u-button>
      </view>
      <h4>用车情况回执</h4>
      <view
        v-for="(item, index) in item.fileJsonVOS"
        :key="index"
        class="right"
      >
        <a style="color: #6483f4" :href="item.fileUrl">
          {{ item.fileName }}
        </a>
        <text style="padding-left: 8%; color: #aab2c8; font-size: 13px"> </text>
      </view>
    </view>
  </view>
</template>

<script>
import {userList  } from "@/api/chapters.js";
import { getdcrList, Upload } from "@/api/vehiclemanagement";
export default {
  name: "MinirabbitSendcar",

  data() {
    return {
      list: [],
      file: [],
      userList:[],
      row: {},
    };
  },
  async onLoad(options) {
    const row = JSON.parse(options.row);
    this.row = row;
    const res=await userList()
    this.userList=res.data.records
    this.getdcrList();
  },
  mounted() {},

  methods: {
    async getdcrList() {
      const res = await getdcrList(this.row);
      this.list = res.data.records;
     
    },
    uploadFile(item) {
      uni.chooseImage({
        success: (chooseImageRes) => {
          const tempFilePaths = chooseImageRes.tempFilePaths;
          uni.uploadFile({
            url: "http://192.168.3.55:1889/api/blade-resource/oss/endpoint/put-file-attach", //仅为示例，非真实的接口地址
            filePath: tempFilePaths[0],
            name: "file",
            formData: {
              // 'user': 'test'
            },
            success: async (uploadFileRes) => {
              const data = JSON.parse(uploadFileRes.data);
             const  file = [
                {
                  fileName: data.data.originalName,
                  fileUrl: data.data.link,
                },
              ];
              const value = {
                id: item.id,
                fileJson: JSON.stringify(file),
              };
              await Upload(value);
              uni.showToast({
                title: "上传成功",
              });
              await this.getdcrList();
            },
          });
        },
      });
    },
    getPass(val, type) {
      return val.map((item) => item[type]).join(",");
    },
  },
};
</script>

<style lang="scss" scoped>
page {
  background-color: #f2f2f2;
}
.contain {
  background-color: #fff;
  width: 100%;
  //   height: 400px;
  margin: 3% 0;
  padding: 20px;
  .contain_box {
    line-height: 42px;
    .contain_left {
      display: inline-block;
      width: 90px;
      color: #aaaaaa;
      padding-right: 4%;
    }
  }
}
h4 {
  line-height: 50px;
}
</style>